// SmartFarmSystem.java
package com.smartfarm.app;

import com.smartfarm.chain.*;
import com.smartfarm.command.*;
import com.smartfarm.factory.*;
import com.smartfarm.observer.*;
import com.smartfarm.domain.*;

public class SmartFarmSystem {
    public static void main(String[] args) {
        // 创建责任链
        SafetyHandler chain = new ObstacleHandler();
        chain.setNext(new FaultHandler());

        // 创建农机
        FarmMachineryFactory factory = new HarvesterFactory();
        FarmMachinery harvester = factory.createMachinery("H001");

        // 配置传感器
        EnvironmentSensor sensor = new EnvironmentSensor();
        sensor.registerObserver(harvester);

        // 模拟系统运行
        sensor.sensorUpdate("土壤湿度正常");
        new StartCommand(harvester).execute();

        sensor.sensorUpdate("检测到障碍物");
        chain.handleRequest("障碍物检测");

        sensor.sensorUpdate("湿度异常警告");
        new StartCommand(harvester).execute();

        sensor.sensorUpdate("发动机温度过高");
        chain.handleRequest("设备故障警报");
    }
}